package myjava.test.ui.model.panel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

/**
 * 自定义一个按钮组件，规范了按钮所需要的方法
 * @author zichaoyang
 */
public class ButtonSet {
	
	protected ArrayList<ActionListener> actionListenerList = new ArrayList<>();

	public synchronized void addActionListener(ActionListener l){
		this.actionListenerList.add(l);
	}
	
	public synchronized void removeActionListener(ActionListener l){
		if(this.actionListenerList.contains(l)){
			this.actionListenerList.remove(l);
		}
	}
	
	@SuppressWarnings("rawtypes")
	public void processEvent(ActionEvent e){
		ArrayList list;
		synchronized (this) {
			if(actionListenerList == null) return;
			list = (ArrayList) this.actionListenerList.clone();
		}
		for (int i = 0; i < list.size(); i++) {
			ActionListener listener = (ActionListener) list.get(i);
			listener.actionPerformed(e);
		}
	}
	
}
